home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 1 / QRZ Ham Radio Callsign Database - December 1993.iso / ucsd / packet / tcpip / amiga / asrc29k.lha / ax25dump.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-08  |  3.6 KB  |  181 lines

  1. #include <stdio.h>
  2. #include "global.h"
  3. #include "mbuf.h"
  4. #include "ax25.h"
  5. #include "timer.h"
  6. #include "lapb.h"
  7. #include "trace.h"
  8. #include "socket.h"
  9.  
  10. static char *decode_type __ARGS((int16 type));
  11.  
  12. /* Dump an AX.25 packet header */
  13. void ax25_dump(fp,bpp,check)
  14. FILE *fp;
  15. struct mbuf **bpp;
  16. int check;    /* Not used */
  17. {
  18.     char tmp[AXBUF];
  19.     char frmr[3];
  20.     char control,pid,seg;
  21.     int16 type;
  22.     int unsegmented;
  23.     struct ax25 hdr;
  24.     char *hp;
  25.  
  26.     fprintf(fp,"AX25: ");
  27.     /* Extract the address header */
  28.     if(ntohax25(&hdr,bpp) < 0){
  29.         /* Something wrong with the header */
  30.         fprintf(fp," bad header!\n");
  31.         return;
  32.     }
  33.     fprintf(fp,"%s",pax25(tmp,hdr.source));
  34.     fprintf(fp,"->%s",pax25(tmp,hdr.dest));
  35.     if(hdr.ndigis > 0){
  36.         fprintf(fp," v");
  37.         for(hp = hdr.digis[0]; hp < &hdr.digis[hdr.ndigis][0];
  38.          hp += AXALEN){
  39.             /* Print digi string */
  40.             fprintf(fp," %s%s",pax25(tmp,hp),
  41.              (hp[ALEN] & REPEATED) ? "*":"");
  42.         }
  43.     }
  44.     if(pullup(bpp,&control,1) != 1)
  45.         return;
  46.  
  47.     fputc(' ',fp);
  48.     type = ftype(control);
  49.     fprintf(fp,"%s",decode_type(type));
  50.     /* Dump poll/final bit */
  51.     if(control & PF){
  52.         switch(hdr.cmdrsp){
  53.         case LAPB_COMMAND:
  54.             fprintf(fp,"(P)");
  55.             break;
  56.         case LAPB_RESPONSE:
  57.             fprintf(fp,"(F)");
  58.             break;
  59.         default:
  60.             fprintf(fp,"(P/F)");
  61.             break;
  62.         }
  63.     }
  64.     /* Dump sequence numbers */
  65.     if((type & 0x3) != U)    /* I or S frame? */
  66.         fprintf(fp," NR=%d",(control>>5)&7);
  67.     if(type == I || type == UI){    
  68.         if(type == I)
  69.             fprintf(fp," NS=%d",(control>>1)&7);
  70.         /* Decode I field */
  71.         if(pullup(bpp,&pid,1) == 1){    /* Get pid */
  72.             if(uchar(pid) == PID_SEGMENT){
  73.                 unsegmented = 0;
  74.                 pullup(bpp,&seg,1);
  75.                 fprintf(fp,"%s remain %u",seg & SEG_FIRST ?
  76.                  " First seg;" : "",seg & SEG_REM);
  77.                 if(seg & SEG_FIRST)
  78.                     pullup(bpp,&pid,1);
  79.             } else
  80.                 unsegmented = 1;
  81.  
  82.             switch(uchar(pid)){
  83.             case PID_SEGMENT:
  84.                 fputc('\n',fp);
  85.                 break;    /* Already displayed */
  86.             case PID_ARP:
  87.                 fprintf(fp," pid=ARP\n");
  88.                 arp_dump(fp,bpp);
  89.                 break;
  90.             case PID_NETROM:
  91.                 fprintf(fp," pid=NET/ROM\n");
  92.                 netrom_dump(fp,bpp);
  93.                 break;
  94.             case PID_IP:
  95.                 fprintf(fp," pid=IP\n");
  96.                 /* Don't verify checksums unless unsegmented */
  97.                 ip_dump(fp,bpp,unsegmented);
  98.                 break;
  99.             case PID_X25:
  100.                 fprintf(fp," pid=X.25\n");
  101.                 break;
  102.             case PID_TEXNET:
  103.                 fprintf(fp," pid=TEXNET\n");
  104.                 break;
  105.             case PID_NO_L3:
  106.                 fprintf(fp," pid=Text\n");
  107.                 break;
  108.             default:
  109.                 fprintf(fp," pid=0x%x\n",uchar(pid));
  110.             }
  111.         }
  112.     } else if(type == FRMR && pullup(bpp,frmr,3) == 3){
  113.         fprintf(fp,": %s",decode_type(ftype(frmr[0])));
  114.         fprintf(fp," Vr = %d Vs = %d",(frmr[1] >> 5) & MMASK,
  115.             (frmr[1] >> 1) & MMASK);
  116.         if(frmr[2] & W)
  117.             fprintf(fp," Invalid control field");
  118.         if(frmr[2] & X)
  119.             fprintf(fp," Illegal I-field");
  120.         if(frmr[2] & Y)
  121.             fprintf(fp," Too-long I-field");
  122.         if(frmr[2] & Z)
  123.             fprintf(fp," Invalid seq number");
  124.         fputc('\n',fp);
  125.     } else
  126.         fputc('\n',fp);
  127.  
  128. }
  129. static char *decode_type(type)
  130. int16 type;
  131. {
  132.     switch(uchar(type)){
  133.     case I:
  134.         return "I";
  135.     case SABM:
  136.         return "SABM";
  137.     case DISC:
  138.         return "DISC";
  139.     case DM:
  140.         return "DM";
  141.     case UA:
  142.         return "UA";
  143.     case RR:
  144.         return "RR";
  145.     case RNR:
  146.         return "RNR";
  147.     case REJ:
  148.         return "REJ";
  149.     case FRMR:
  150.         return "FRMR";
  151.     case UI:
  152.         return "UI";
  153.     default:
  154.         return "[invalid]";
  155.     }
  156. }
  157.  
  158. /* Return 1 if this packet is directed to us, 0 otherwise. Note that
  159.  * this checks only the ultimate destination, not the digipeater field
  160.  */
  161. int ax_forus(iface,bp)
  162. struct iface *iface;
  163. struct mbuf *bp;
  164. {
  165.     struct mbuf *bpp;
  166.     char dest[AXALEN];
  167.  
  168.     /* Duplicate the destination address */
  169.     if(dup_p(&bpp,bp,0,AXALEN) != AXALEN){
  170.         free_p(bpp);
  171.         return 0;
  172.     }
  173.     if(pullup(&bpp,dest,AXALEN) < AXALEN)
  174.         return 0;
  175.     if(addreq(dest,iface->hwaddr))
  176.         return 1;
  177.     else
  178.         return 0;
  179. }
  180.  
  181.